import {
  batchCreate,
  batchDel,
  create,
  del,
  detail,
  download,
  edit,
  list,
  page,
  type R,
  upload
} from "@/api";
import { http } from "@/utils/http";

const path = "/api/v1/system/department";
const customPath = "/api/v1/dept";

enum Index {
  listCustom = "/list",
  createCustom = "/create",
  editCustom = "/edit"
}

export type Record = {
  name: string;
  parentId: number;
  id: number;
  sort: number;
  phone: string;
  principal: string;
  email: string;
  status: number;
  type: number;
  createTime: string;
  remark: string;
};

export type ListResult = Array<Record>;

export const apiPage: (data?: object) => Promise<R> = (data?: object) =>
  page(path, data);

export const apiList: (data?: object) => Promise<R> = (data?: object) =>
  list(path, data);

export const apiDetail = (id?: string) => detail(path, id);

export const apiCreate = (data?: object) => create(path, data);

export const apiBatchCreate = (data?: object) => batchCreate(path, data);

export const apiEdit = (data?: object) => edit(path, data);

export const apiDel = (id?: string) => {
  return del(path, id);
};

export const apiBatchDelete = (data?: object) => batchDel(path, data);

export const apiDownload = (params?: object, data?: object, isXlsx = false) =>
  download(path, params, data, isXlsx);

export const apiUpload = (data?: object) => upload(path, data);

export const listCustom = (data?: object) =>
  http.post<R<ListResult>, {}>(`${customPath}${Index.listCustom}`, {
    data: data
  });

export const createCustom = (data?: object) =>
  http.post<R, {}>(`${customPath}${Index.createCustom}`, { data: data });

export const editCustom = (data?: object) =>
  http.post<R, {}>(`${customPath}${Index.editCustom}`, { data: data });
